/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-12     liuchao       the first version
 */
#define LOG_TAG "lock_switch"
#include "drv_lock_switch.h"
#include <ulog.h>
const char* lock_switch_name(lock_switch_e lock_switch)
{
    switch (lock_switch)
    {
    case LOCK_SWITCH_2MM:
        return "2MM";
    case LOCK_SWITCH_4MM:
        return "4MM";
    default:
        return "UNKNOWN";
    }
}

int lock_switch_read(lock_switch_e lock_switch)
{
    int ret = 0;
    switch (lock_switch)
    {
    case LOCK_SWITCH_2MM:
        ret = rt_pin_read(LOCK_SWITCH_2MM_PIN);
        break;
    case LOCK_SWITCH_4MM:
        ret = rt_pin_read(LOCK_SWITCH_4MM_PIN);
        break;
    default:
        LOG_E("Invalid lock switch %d", lock_switch);
        break;
    }
    return ret;
}

lock_switch_state_e lock_switch_state(lock_switch_e lock_switch)
{
    if (lock_switch_read(lock_switch) == PIN_LOW)
    {
        return LOCK_SWITCH_STATE_ACTIVE;
    }
    return LOCK_SWITCH_STATE_INACTIVE;
}

static int init_lock_switch()
{
    rt_pin_mode(LOCK_SWITCH_2MM_PIN, PIN_MODE_INPUT_PULLUP);
    rt_pin_mode(LOCK_SWITCH_4MM_PIN, PIN_MODE_INPUT_PULLUP);
    return RT_EOK;
}
INIT_COMPONENT_EXPORT(init_lock_switch);
